package com.hspedu.newData.dmsxl.字符串;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-22 
 * @Version: 1.0
 */

public class LC541反转字符串Ⅱ {

    // todo
    public String reverseStr(String s, int k) {
        char[] charArray = s.toCharArray();
        int n = charArray.length;
        for (int i = 0; i < charArray.length; ) {
            reverseString(charArray,i,Math.min(i+k,n) - 1);
            i = i + 2*k;
        }
        return charArray.toString();
    }


    public void reverseString(char[] s,int start,int end) {
        int left = start;
        int right = end;
        while(left <= right){
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            left++;
            right--;
        }
    }
}
